package pl.edu.uj.tcs.hkextended;

import java.util.List;

import org.pocketworkstation.pckeyboard.Dictionary;
import org.pocketworkstation.pckeyboard.WordComposer;

public class GoogleXMLDictionary extends Dictionary {
	private XMLParser parser;
	private GoogleXMLFactory factory;
	
	public GoogleXMLDictionary(XMLParser parser) {
		this.parser = parser;
		this.factory = new GoogleXMLFactory();
	}
	
	@Override
	public void getWords(WordComposer composer, WordCallback callback,
			int[] nextLettersFrequencies) {
		String xml = factory.get(composer.getTypedWord());
		List<SuggestItem> items = (List<SuggestItem>) parser.parse(xml);
		for (SuggestItem item : items) {
			callback.addWord(item.getSuggest().toCharArray(), 0, item.getSuggest().length(), item.getPriority(), 
					255, DataType.BIGRAM);
		}
	}

	@Override
	public boolean isValidWord(CharSequence word) {
		return true;
	}

}
